package edu.szu.huhanpeng.doodlingFight.controller.showController.exchange 
{
	import com.aka.tools.animation.TurnToChange;
	import edu.szu.huhanpeng.doodlingFight.globalConst.GlobalConst;
	import edu.szu.huhanpeng.doodlingFight.interfaces.IChessData;
	import edu.szu.huhanpeng.doodlingFight.interfaces.ISquareData;
	import edu.szu.huhanpeng.doodlingFight.model.ChessBoardProxy;
	import edu.szu.huhanpeng.doodlingFight.view.ChessMediator;
	import edu.szu.huhanpeng.doodlingFight.view.StageMed;
	import flash.display.DisplayObject;
	import flash.display.Stage;
	import flash.events.Event;
	import org.puremvc.as3.interfaces.IAsyncCommand;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.interfaces.INotifier;
	import org.puremvc.as3.patterns.command.AsyncCommand;
	
	/**
	 * ...
	 * @author Huhanpeng
	 */
	public class ChangeTwoChessSc extends AsyncCommand implements IAsyncCommand, INotifier 
	{
		/**
		 * noteName:	EXCHANGE
		 * noteBody:	Vector.<IChessData>,元素为交换的两个棋子data
		 * noteType:	
		 */
		override public function execute(note:INotification):void 
		{
			var changeVec:Vector.<IChessData> = note.getBody() as Vector.<IChessData>;
			
			if (changeVec.length != 2 ) 
			{
				if ( GlobalConst.setting.DEBUG == true ) 
				{
					throw new Error( "转换成功命令中要转换的棋子个数必须为2" );
				}
					return;
			}
			
			//显示动画
			var chessAMed:ChessMediator = facade.retrieveMediator(changeVec[0].name) as ChessMediator;
			var chessBMed:ChessMediator = facade.retrieveMediator(changeVec[1].name) as ChessMediator;
			var stageMed:StageMed = facade.retrieveMediator(StageMed.NAME) as StageMed;
			
			var animation:TurnToChange = new TurnToChange(chessAMed.getViewComponent() as DisplayObject, chessBMed.getViewComponent() as DisplayObject, stageMed.getViewComponent() as Stage, 300, TurnToChange.HIGH);
			animation.addEventListener(TurnToChange.DONE, ondone);
			animation.start();
		}
		
		private function ondone(e:Event):void 
		{
			commandComplete();
		}
		
	}

}